package com.ww.mock;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ww.utils.HttpPrintUtils;

public class DSHandler extends AbstractHandler {

	@Override
	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		String query = request.getParameter("query");
		
		if(null != query && query.equals("getsubjectinfo")){
			JSONObject json = new JSONObject();
			json.put("code", 200);
			json.put("message", "获取产品信息成功");
			
			JSONObject subJson = new JSONObject();
			subJson.put("sname", "科目一");
			
			JSONArray vipArr = new JSONArray();
			JSONObject tc1 = new JSONObject();
			tc1.put("pid", "p1");
			tc1.put("pname", "1小时VIP学车");
			tc1.put("price", 200);
			
			JSONObject tc2 = new JSONObject();
			tc2.put("pid", "p2");
			tc2.put("pname", "2小时VIP学车");
			tc2.put("price", 300);
			vipArr.add(tc1);
			vipArr.add(tc2);
			
			JSONArray nvipArr = new JSONArray();
			JSONObject tc3 = new JSONObject();
			tc3.put("pid", "p3");
			tc3.put("pname", "1小时学车");
			tc3.put("price", 100);
			
			JSONObject tc4 = new JSONObject();
			tc4.put("pid", "p4");
			tc4.put("pname", "2小时学车");
			tc4.put("price", 150);
			nvipArr.add(tc3);
			nvipArr.add(tc4);
			
			subJson.put("vip", vipArr);
			subJson.put("nvip", nvipArr);
			
			
			JSONObject subJson2 = new JSONObject();
			subJson2.put("sname", "科目二");
			
			JSONArray vipArr2 = new JSONArray();
			JSONObject tc12 = new JSONObject();
			tc12.put("pid", "p12");
			tc12.put("pname", "1小时VIP学车2");
			tc12.put("price", 200);
			
			JSONObject tc22 = new JSONObject();
			tc22.put("pid", "p22");
			tc22.put("pname", "2小时VIP学车2");
			tc22.put("price", 300);
			vipArr2.add(tc12);
			vipArr2.add(tc22);
			
			subJson2.put("vip", vipArr2);
			
			JSONArray subArr = new JSONArray();
			subArr.add(subJson);
			subArr.add(subJson2);
			json.put("subject", subArr);
			
			HttpPrintUtils.printToJson(json.toJSONString(), response);
		}
	}
	
	
}
